﻿

@model PagedList<Views_Goods>
@{
    ViewBag.Title = "编辑竞价商品";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";

    JingjiaGoodsQueryModel paramModel = new JingjiaGoodsQueryModel();
    if (ViewBag.paramModel != null)
    {
        paramModel = (JingjiaGoodsQueryModel)ViewBag.paramModel;
    }
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();

}
@if (paramModel.jingjia_id > 0)
{
    var aDZ_JingjiaMaster = dbcontext.ADZ_JingjiaMaster.FirstOrDefault(t => t.jingjia_id == paramModel.jingjia_id);

    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td style="width:300px">
                <h5>@ViewBag.Title   当前竞价【@aDZ_JingjiaMaster.jingjia_name】包含以下商品</h5>
            </td>
            <td><button type="button" backpageid="jingjia/add" class="btn btn-success" name="backid" id="backid">返回详情</button></td>
        </tr>
    </table>
    <table class="table table-bordered table-hover definewidth m10">
        <thead>
            <tr>
                <th>序号</th>
                <th style="width:70px">图片</th>
                <th>料号</th>
                <th>品牌</th>
                <th>分类</th>
                <th>供应商</th>
                <th>DC号</th>
                <th>上架时间</th>
                <th>是否含税</th>
                <th>库存数量</th>
                <th>备注</th>
                <th></th>
            </tr>
        </thead>
        @{
            var goods_ids =
                from t in dbcontext.ADZ_GoodsJingjia
                where t.jingjia_id.Equals(paramModel.jingjia_id)
                select t.goods_id;
            var good_list = dbcontext.Views_Goods.Where(t => goods_ids.Contains(t.goods_id) && t.is_del == 0);

            int index = 0;
            foreach (var m in good_list)
            {
                index++;
                <tr class="@HtmlPagerHelper.TrClass(index)">
                    <td>@m.goods_id</td>
                    <td>
                        @{
                            var aDZ_GoodsIMGs = dbcontext.ADZ_GoodsIMG.Where(t => t.goods_id == m.goods_id);
                            foreach (var item in aDZ_GoodsIMGs.OrderBy(t => t.sort_NO))
                            {
                                <a href="@ImageFileBiz.GetImg(item.img_url)" target="_blank"> <img style="width:30px;margin:1px 1px 1px 1px;" src="@ImageFileBiz.GetImg(item.img_url,"small")" /></a>
                            }
                        }
                    </td>
                    <td>@m.MPN</td>
                    <td>@m.brand_name</td>
                    <td>@m.category_name</td>
                    <td>@m.supplier_name</td>
                    <td>@m.DCN</td>
                    <td>@m.with_up_time.ToString(1)</td>
                    <td>
                        @if (m.include_tax == 0)
                        {
                            <info>未含税</info>
                        }
                        else if (m.include_tax == 1)
                        {
                            <info class="green">含税</info>
                        }
                    </td>
                    <td>@m.stock_amount @m.goods_unit</td>
                    <td>@m.product_desc</td>
                    <td>
                        <a href="@Url.Action("detailInfo", "product", new { id = m.goods_id})">查看</a>
                        <a href="javascript:void(0);" onclick="moveout(@m.goods_id)">移出竞价包</a>
                    </td>
                </tr>
            }
        }
    </table>
}
<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <td colspan="2" style="width:50%">
            <h5>以下未配置到竞价包中的商品可以添加到此竞价包中 <info class="red">请谨慎操作</info></h5>
        </td>
    </tr>
</table>
<form id="S_Form" class="form-inline definewidth m20" action="@Url.Action("editgoods", "jingjia")" method="get">
    <input type="hidden" value="@paramModel.jingjia_id" name="jingjia_id" />
    <div class="form_query">
        <div>
            序号：
            <input type="text" name="goods_id" id="goods_id" class="abc input-default" placeholder="" value="@paramModel.goods_id">&nbsp;
        </div>
        <div>
            料号：
            <input type="text" name="MPN" id="MPN" class="abc input-default" placeholder="" value="@paramModel.MPN">&nbsp;
        </div>
        <div>
            品牌：
            <select id="label_type" name="brand_id">
                <option value="-10">全部品牌</option>
                @{
                    dc = new Dictionary<string, string>();
                    dbcontext.ADZ_BrandMaster.Where(t => t.is_del == 0).ToList().ForEach(t =>
                    {
                        dc.Add(t.brand_id.ToString(), t.brand_name);
                    });
                }
                @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.brand_id.ToString())
            </select>&nbsp;
        </div><div>
            分类：
            <select id="category_id" name="category_id">
                <option value="-10">全部分类</option>
                @{
                    dc = new Dictionary<string, string>();
                    ADZ_GoodsCategoryBiz.Instance.GetParentSunList().ForEach(t =>
                    {
                        dc.Add(t.category_id.ToString(), t.category_name);
                    });
                }
                @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.category_id.ToString())
            </select>&nbsp;
        </div><div>
            供应商：
            <select id="supplier_id" name="supplier_id">
                <option value="-10">全部供应商</option>
                @{
                    dc = new Dictionary<string, string>();
                    dbcontext.ADZ_SupplierMaster.Where(t => t.is_del == 0).ToList().ForEach(t =>
                    {
                        dc.Add(t.supplier_id.ToString(), t.supplier_name);
                    });
                }
                @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.supplier_id.ToString())
            </select>&nbsp;
        </div>
        <div>
            @{Html.RenderPartial(Url.Content("~/Views/Common/PageSize.cshtml"), paramModel);}
        </div><div>
            <button type="submit" class="btn btn-primary" id="formsubmit">查询</button>&nbsp;&nbsp;
        </div>
    </div>
</form>

<table class="table table-bordered table-hover definewidth m10">
    <thead>
        <tr>
            <th style="width:40px"><input type="checkbox" name="chkall" id="chkall" />全选</th>
            <th style="width:70px">图片</th>
            <th>料号</th>
            <th>品牌</th>
            <th>分类</th>
            <th>供应商</th>
            <th>DC号</th>
            <th>上架时间</th>
            <th>是否含税</th>
            <th>库存数量</th>
            <th>备注</th>
            <th></th>
        </tr>
    </thead>
    @if (Model != null && Model.Count != 0)
    {
        int index = 0;
        foreach (var m in Model)
        {
            index++;
            <tr class="@HtmlPagerHelper.TrClass(index)">
                <td>
                    <input type="checkbox" name="cbx_last" value="@m.goods_id" />@m.goods_id
                </td>
                <td style="padding:5px 0 0 2px;">
                    @{
                        var aDZ_GoodsIMGs = dbcontext.ADZ_GoodsIMG.Where(t => t.goods_id == m.goods_id).OrderBy(t => t.sort_NO).ThenBy(t => t.seq_id);
                        foreach (var item in aDZ_GoodsIMGs.OrderBy(t => t.sort_NO))
                        {
                            <a class="list-img" href="@ImageFileBiz.GetImg(item.img_url)" target="_blank"> <img style="width:30px;margin:1px 1px 1px 1px;" src="@ImageFileBiz.GetImg(item.img_url,"small")" /></a>
                        }
                    }
                </td>
                <td>@m.MPN</td>
                <td>@m.brand_name</td>
                <td>@m.category_name</td>
                <td>@m.supplier_name</td>
                <td>@m.DCN</td>
                <td>@m.with_up_time.ToString(1)</td>
                <td>
                    @if (m.include_tax == 0)
                    {
                        <info>未含税</info>
                    }
                    else if (m.include_tax == 1)
                    {
                        <info class="green">含税</info>
                    }
                </td>
                <td>@m.stock_amount @m.goods_unit</td>
                <td>@m.product_desc</td>
                <td>
                    <a href="@Url.Action("detailInfo", "product", new { id = m.goods_id})">查看</a>
                    <a href="javascript:void(0);" onclick="movein(@m.goods_id)">加入竞价包</a>
                </td>
            </tr>
        }
        <tr>
            <td colspan="20">
                <a href="javascript:void(0);" onclick="movemorein()">选择项加入竞价包</a>
            </td>
        </tr>
    }
</table>
<div class="inline pull-left total">
    总行数：@ViewData["AllCount"]
</div>
<div class="inline pull-right page">
    @if (Model != null)
    {
        @Html.Pager(Model, HtmlPagerHelper.BasePagerOption)
    }
</div>
<script>
    var cancelButton =
        {
            text: '取消',
            elCls: 'button',
            handler: function () {
                this.close();
            }
        };
    reloadHandler = function () {
        window.location.reload();
    };
    function moveout(id) {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要将该物料移出此竞价包吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("doeditgoods", "jingjia")";
                      parameter = {
                          inout:1,//1移除 2 加入
                          goods_id: id,
                          jingjia_id: @paramModel.jingjia_id
                      };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
                },
                cancelButton
            ]
        });
    }
    function movein(id) {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要将该物料加入此竞价包吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("doeditgoods", "jingjia")";
                      parameter = {
                          inout : 2,
                          goods_id: id,
                          jingjia_id: @paramModel.jingjia_id
                      };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
                },
                cancelButton
            ]
        });
    }
    function movemorein() {
        alert(1);
        var ids = getCheckboxList();
        if (ids.length == 0) {
            BUI.Message.Alert("请选择要加入竞价包的数据", 'warning');
            return;
        }
        alert(ids);
        BUI.Message.Show({
            title: '提示',
            msg: '确定要将选择的物料都加入竞价包吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("doeditmoregoods", "jingjia")";
                      parameter = {
                            inout : 2,
                            jingjia_id: @paramModel.jingjia_id,
                            goods_ids: ids
                      };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
              },
                cancelButton

            ]
        });
    }
</script>
